import com.sun.javafx.sg.prism.web.NGWebView;
import com.sun.org.apache.bcel.internal.generic.NEW;
import java.io.DataOutput;
import java.util.Calendar;
import java.util.Scanner;
import javax.xml.transform.Source;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 9:08
 * @description:测试类
 */
public class UserTest {
  private static UserDao dao=new UserDaoMap();

  public static void main(String[] args) {

    while (true){
      System.out.println("-----欢迎光临-----");
      System.out.println("1 注册");
      System.out.println("2 登录");
      System.out.println("3 查询所有");
      System.out.println("4 退出");
      System.out.println("请输入你的选择");
      Scanner sc=new Scanner(System.in);
      int num=sc.nextInt();
      switch (num){
        case 1:
          registerFace();
          break;
        case 2:
          loginFace();
          break;
        case 3:
          queryAllFace();
          break;
        case 4:
          System.exit(0);
          System.out.println("欢迎下次光临");
          break;
        default:
          System.out.println("输入有误");
          break;
      }
    }

  }

  private static void queryAllFace() {
    System.out.println("-----查询所有界面-----");
    dao.queryAll();
  }

  private static void loginFace() {
    System.out.println("-----登录界面-----");
    Scanner sc=new Scanner(System.in);
    System.out.println("请输入用户名");
    String name=sc.nextLine();
    System.out.println("请输入密码");
    String password=sc.nextLine();
    boolean flag=dao.login(name,password);
    if (flag){
      System.out.println("登陆成功，可以玩小游戏了！");
    }else {
      System.out.println("失败！用户名或密码错误！");
    }
  }

  private static void registerFace() {
    System.out.println("-----注册界面-----");
    Scanner sc=new Scanner(System.in);
    Scanner sc1=new Scanner(System.in);
    System.out.println("请输入学号：");
    int id=sc.nextInt();
    System.out.println("请输入用户名：");
    String name=sc1.nextLine();
    System.out.println("请输入密码：");
    String password=sc1.nextLine();
    System.out.println("请输入年龄：");
    int age=sc.nextInt();
    User user=new User(id,name,password,age);
    dao.register(user);
    System.out.println("注册成功！");
  }
}
